package view;

import android.text.TextUtils;
import android.widget.ImageView;

import com.example.xuegengwang.xuegengwang.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import utils.VariousUtils;

/**
 * Created by Administrator on 2017/3/25.
 */

public class MyImageLoader {

    public static void showImage(String url, ImageView imageView) {
        showImage(url, imageView, null);
    }

    public static void showImage(String url, ImageView imageView, ImageLoadingListener imageLoadingListener) {
        if (url!=null) {
            if (!TextUtils.isEmpty(url)) {
                if (url.contains("https")) {
                    url = VariousUtils.noHttps(url);
                    try {
                        if (imageLoadingListener != null) {
                            ImageLoader.getInstance().displayImage(url, imageView, imageLoadingListener);
                        } else {
                            ImageLoader.getInstance().displayImage(url, imageView);
                        }
                    } catch (Exception e) {
                    }
                } else {
                    try {
                        if (imageLoadingListener != null) {
                            ImageLoader.getInstance().displayImage(url, imageView, imageLoadingListener);
                        } else {
                            ImageLoader.getInstance().displayImage(url, imageView);
                        }
                    } catch (Exception e) {
                    }
                }
            } else {
                imageView.setImageResource(R.mipmap.default_ima);
            }
        } else {
            imageView.setImageResource(R.mipmap.default_ima);
        }
    }
}
